# -*- coding: utf-8 -*-

__author__ = """WebLion <support@weblion.psu.edu>"""
__docformat__ = 'plaintext'

#
# Test-cases for class(es) GroupsFolder
#

from Products.ContactsDirectory.config import *
from Products.ContactsDirectory.tests.testPlone import testPlone

class testGroupsFolder(testPlone):
    """Test-cases for class(es) GroupsFolder."""

    def afterSetUp(self):
        self.loginAsPortalOwner()

    def testFTISetup(self):
        """ Make sure the FTI is pulling info from the GS types profile """
        self.failUnless(self.portal.portal_types['CDOrganization'].Title() != "AT Content Type")

    def testGroupCreation(self):
        """Make sure we can add Group objects within the GroupsFolder."""
        cd = self.getPopulatedDirectory()
        self.failUnless('groups' in cd.contentIds(), "Failed to create a GroupsFolder in the ContactsDirectory.")
        group = cd['groups']
        group.invokeFactory(type_name="CDGroup", id="test_group")
        self.failUnless('test_group' in group.contentIds(), "Failed to create a Group in the GroupsFolder.")

    def testObjectReorder(self):
        """ Make sure we can reorder objects within this folderish content type. """
        cd = self.getPopulatedDirectory()
        group = cd['groups']
        group.invokeFactory(type_name="CDGroup", id="o1") 
        group.invokeFactory(type_name="CDGroup", id="o2") 
        group.invokeFactory(type_name="CDGroup", id="o3") 
        group.moveObjectsByDelta(['o3'], -100)
        self.failUnless(group.getObjectPosition('o3') == 0, "CDGroup Subobject 'o3' should be at position 0.")

def test_suite():
    from unittest import TestSuite, makeSuite
    suite = TestSuite()
    suite.addTest(makeSuite(testGroupsFolder))
    return suite
